<template>
	<view>
		<view class="lb-main-32">
			<view class="lb-item">
				<view class="item-left">
					数量
				</view>
				<view class="item-right">
					<input type="number" v-model="FormData.num" placeholder="请输入"
						placeholder-style="font-size: 28rpx; color: #999999;">
				</view>
			</view>
			<view class="lb-item">
				<view class="item-left">
					验证码
				</view>
				<view class="item-right">
					<input disabled v-model="FormData.code" placeholder-style="font-size: 28rpx; color: #999999;">
				</view>
				<view class="copy" @click="getCodeImg">{{FormData.code?'复制':'获取'}}</view>
			</view>

			<button class="lb-btn" open-type="share" :data-id="crrGood.sid" :data-name="crrGood.goods.name"
				:data-img="crrGood.goods.cover_image" :data-sid="crrGood.sid">
				赠送
			</button>
		</view>
	</view>
</template>

<script>
	import {
		getCode,
		giveSave
	} from "@/api/apis/comm.js"
	import {
		mobile,
		account,
		setImgUrl,
		fmtFormat
	} from "@/utils/comm.js"
	export default {
		data() {
			return {
				FormData: {
					code: ''
				},
				crrGood: {}
			}
		},
		onLoad(e) {
			this.crrGood = JSON.parse(e.json)
			this.FormData.s_id = this.crrGood.sid
			this.FormData.m_id = this.crrGood.id
		},
		async onShareAppMessage(res) {
			if (res.from === 'button') {
				let give = await giveSave(this.FormData)
				let dataset = res.target.dataset;
				let gName = dataset.name;
				let img = setImgUrl(dataset.img);
				let gid = dataset.id;
				let sid = dataset.sid;
				let uid = this.user_info.id;
				let url = '/pages/channel/goods-detail/goods-detail'
				return {
					title: gName,
					imageUrl: img,
					path: url + '?type=3&sid=' + sid + '&uid=' + uid + '&id=' + gid + '&giveid=' + give.data
				}
			}
		},
		async onShareTimeline(res) {
			if (res.from === 'button') {
				let give = await giveSave(this.FormData)
				let dataset = res.target.dataset;
				let gName = dataset.name;
				let img = setImgUrl(dataset.img);
				let gid = dataset.id;
				let sid = dataset.sid;
				let uid = this.user_info.id;
				let url = '/pages/channel/goods-detail/goods-detail'
				return {
					title: gName,
					imageUrl: img,
					path: url + '?type=3&sid=' + sid + '&uid=' + uid + '&id=' + gid + '&giveid=' + give.data
				}

			}

		},

		methods: {
			getCodeImg() {
				if (this.FormData.code) {
					uni.setClipboardData({
						data: this.FormData.code,
						success: function() {
							console.log('success');
						}
					});
					return
				}
				getCode().then(res => {
					this.FormData.code = res.data
				})
			},
		},

	}
</script>

<style lang="scss">
	page {
		background-color: #FFFFFF;
	}

	.lb-tip {
		font-size: $main-font-20;
		color: #F65D40;
		padding: 12rpx 0;
	}

	.lb-item {
		width: 100%;
		display: flex;
		flex-direction: row;
		align-items: center;
		padding: 42rpx 0 24rpx 0;
		border-top: 2rpx solid #F5F5F5;

		&:nth-of-type(1) {
			border: none;
			padding-top: 10rpx;
		}

		.item-left {

			width: 200rpx;
			font-size: $main-font-28;
			color: $main-font-color;
			white-space: nowrap;

			&::before {
				content: '* ';
				color: #F65D40;
			}
		}

		.item-right {
			flex: 1;
			display: flex;
			flex-direction: row;
			justify-content: flex-end;

			input {
				width: 100%;
				text-align: right;
				font-size: $main-font-28;
				color: $main-font-color;
			}

			.right-icon {
				display: flex;
				flex-direction: row;
				padding: 12rpx;
			}

		}

		.copy {
			color: #F7583F;
			padding: 0 20rpx;
		}

	}


	.lb-btn {
		margin: 50rpx auto;
		width: 600rpx;
		height: 88rpx;
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		margin-right: 24rpx;
		background: linear-gradient(106deg, #F7583F 0%, #F28F4C 100%);
		border-radius: 24rpx;
		font-size: $main-font-24;
		color: $main-font-color-white;

		&:nth-of-type(2n-1) {
			background: linear-gradient(106deg, #FFC67D 0%, #FF8F35 100%);
		}
	}
</style>